import { useState, useEffect } from 'react';
import { http } from '../utils/http';

export const App = () => {
  const [count, setCount] = useState(0);
  useEffect(() => {
    // 在组件渲染完毕后发起请求
    // async function fetchData() {
    //   const res = await http.get('https://toutiao.itheima.net/v1_0/channels');
    //   console.log(res);
    // }
    // fetchData();
    (async function () {
      const res = await http.get('https://toutiao.itheima.net/v1_0/channels');
      console.log('立即调用函数表达式', res);
    })();

    // http.get('https://toutiao.itheima.net/v1_0/channels').then((res) => {
    //   console.log(res.data);
    // });
  }, []);

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </div>
  );
};
